<?php

namespace Assets\UploadBundle\Controller;

use Base\BaseController;
use BaseExt\PicUpload;
use Monolog\Handler\StreamHandler;
use Symfony\Bridge\Monolog\Logger;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\JsonResponse;

class MyUploadController extends BaseController
{

    /**
     * @Route("/MyWebPicUpload" , name="MyWebPicUpload")
     */
    public function MyWebPicUpload()
    {
        if (!$name = $this->getParamRequired("name")) {
            $name = "Filedata";
        }
//        $logger = $this->get("logger");
//        $logger->info("-------------------------------");
//        $logger->info(json_encode($_FILES));
//        $logger->info(json_encode($_POST));
//        $logger->info(json_encode($_GET));
//        $logger->info(json_encode($_REQUEST));
//        $logger->info("-------------------------------");
        $picUploadModel = new PicUpload();
//        $logger = $this->get("logger");
//        $logger->info("-------------------------------");
//        $postName = $name;
//        if (is_string($postName)) {
//            $postName = array($postName);
//        }
//        sort($postName);
//        $postKeys = array_keys($_FILES);
//        sort($postKeys);
//
//        $logger->info(json_encode($postName));
//        $logger->info(json_encode($postKeys));
//        $logger->info(json_encode($_FILES));
//        $logger->info("-------------------------------");
        $rst = $picUploadModel->doUpload($name);
        $data = $picUploadModel->getData();
        if ($data) {
            $re = array(
                "s"=>1,
                "i"=>"上传成功",
                "d"=>$data[$name],
            );
        } else {
            $re = $rst;
        }
        return new JsonResponse($re);
    }
}
